require(["tools"], function(util) 
{
    alert("tools ready")
});

function network(){};
network.prototype.ajaxPost = function(url, callbackfunc, resent)
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();
    }
    else
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            ret = stringtojson(xmlhttp.responseText);
            callbackfunc(ret);
        }
        else if (xmlhttp.readyState == 4 && xmlhttp.status != 200)
        {
            if(resent)
            {
                xmlhttp.open("GET",url,true);
                xmlhttp.send();
            }
            else
            {
                alert(NT_NW_errortitle, NT_AJAX_errorcontent);
                callbackfunc(null);
            }
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}
network.prototype.ajaxGet = function(url, callbackfunc, resent)
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            ret = stringtojson(xmlhttp.responseText);
            callbackfunc(ret);
        }
        else if (xmlhttp.readyState==4 && xmlhttp.status!=200)
        {
            if( resent )
            {
                xmlhttp.open("GET",url,true);
                xmlhttp.send();
            }
            else
            {
                Ext.Msg.alert(NT_NW_errortitle, NT_AJAX_errorcontent);
                callbackfunc(null);
            }
        }
    }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}
network.prototype.webConnect = function(url, callbackfunc)
{
    if( ASOIAF.network.Common.socket != null )
    {
        Ext.Msg.alert(NT_NW_errortitle , NT_WEBSOCKET_reconnecterror)
    }
    ASOIAF.network.Common.socket = new WebSocket(url);
    ASOIAF.network.Common.socket.onopen = callbackfunc
    ASOIAF.network.Common.socket.onclose  = function()
    {
        alert(NT_WEBSOCKET_error)
        exitgame()
    }
    ASOIAF.network.Common.socket.onmessage = function(evt)
    {
        if( ASOIAF.network.Common.socketcallback != null )
        {
            ASOIAF.network.Common.socketcallback(evt)
        }
    }
}
var network = null


Ext.define('ASOIAF.network.Common',
{
    statics:
    {
        socket: null,
        socketcallback: null,
        
        
        
        ajaxPost: 
        
        
        webConnect: function(url, callbackfunc)
        
            
        webSend: function( item , callbackfunc )
        {
            if( ASOIAF.network.Common.socket == null )
            {
                Ext.Msg.alert(NT_NW_errortitle , NT_WEBSOCKET_notconnected);
            }
            string = ASOIAF.network.Common.jsontostring(item);
            ASOIAF.network.Common.socketcallback = callbackfunc
            ASOIAF.network.Common.socket.send(string);
        }
    }
});